 import 'dart:convert';

class BleBeanInterface {
  /// 蓝牙名称
  String name = "";

  /// 蓝牙地址(或者唯一标识)
  late String address;

  ///广播数据
  late List bytes;

  ///mtu大小
  int mtu = 20;

  ///信号强度
  int rssi = 0;

  ///是否已经连接
  bool isConnect = false;

  ///真实的mac地址
  String mac = "";


  String toJson(){
    return '{"name": "$name", "address": "$address", "bytes": $bytes, "mtu": $mtu, "rssi": $rssi, "isConnect": $isConnect, "mac": "$mac"}';
  }

  static BleBeanInterface fromJson(String jsonStr) {
    Map<String, dynamic> json = jsonDecode(jsonStr);
    BleBeanInterface bean = BleBeanInterface();
    bean.name = json['name'];
    bean.address = json['address'];
    bean.bytes = json['bytes'];
    bean.mtu = json['mtu'];
    bean.rssi = json['rssi'];
    bean.isConnect = json['isConnect'];
    bean.mac = json['mac'];
    return bean;
  }


  /// 重写 == 方法
  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true; // 引用相等
    return other is BleBeanInterface && other.address == address;
  }

  // 重写 hashCode 方法
  @override
  int get hashCode => address.hashCode;
}
